<cfcomponent output="false">
	<cfset $ = application.helpers />
	<cfset $service = application.s />
	
	<cfset THIS.browse = "ID,Location,Email,Name,Created," />

	<!--- --->
	
	<cffunction name="_renderForm" access="public" output="true" returntype="string">
		<cfargument name="title" required="true" />
		<cfargument name="id" required="false" default="" />
		<cfargument name="collapse" requried="false" default="true" />
		<cfargument name="leftButton" required="false" default="" />
		<cfargument name="leftAction" required="false" default="" />
		<cfargument name="rightButton" required="false" default="" />
		<cfargument name="rightAction" required="false" default="" />
		
		<cfset var local = {} />
		
		<cfif arguments.id eq ""><cfset arguments.id = arguments.title /></cfif>
		
		<cfsavecontent variable="local.result">
			<div class="filterSet-wrapper">
				<div class="filterSet-title <cfif arguments.collapse>collapse</cfif>" id="filter_#arguments.id#" <cfif arguments.collapse>onclick="javascript:Filter.toggle('#arguments.id#');"</cfif>>
					<cfif arguments.collapse>
						#$.render.img(path='icons/arrow_up.png',style="margin-bottom:-1px;height:13px;margin-left:-13px;margin-right:5px;",id="#arguments.id#_up")#
						#$.render.img(path='icons/arrow_down.png',style="margin-bottom:-1px;height:13px;margin-left:-13px;display:none;margin-right:5px;",id="#arguments.id#_down")#
					</cfif>
					<cfif arguments.leftButton neq ''>
						<a class="title-sideButtons" href="javascript:#arguments.leftAction#" style="float:left;">#arguments.leftButton#</a>
					</cfif>
					<span class="theTitle">#arguments.title#</span>
					<cfif arguments.rightButton neq ''>
						<a class="title-sideButtons" href="javascript:#arguments.rightAction#" style="float:right;">#arguments.rightButton#</a>
					</cfif>
					<div class="validation-messages"></div>
				</div>
				<div class="filterSet <cfif arguments.collapse>left</cfif>" id="filterSet_#arguments.id#">
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
	</cffunction>
	
	<!--- --->
	
	<cffunction name="formClose" access="public" output="true" returntype="string">
		
		<cfset var local = {} />
		
		<cfsavecontent variable="local.result">
				</div>
			</div>
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
	</cffunction>
	
	<!--- --->
	
	<cffunction name="renderBrowseFilter" access="public" output="true" returntype="string">
		
		<cfset var local = {} />
		
		<cfsavecontent variable="local.result">
			#_renderForm("Search")#
				#renderTitleDescriptionFilter()#
				#renderIDFilter()#
				#renderLocationFilter()#
				#renderOwnerFilter()#
				#renderDateRangeFilter()#
				<div class="logged-in" <cfif session.loggedin neq 1>style="display:none;"</cfif>>
					#renderSorting()#
				</div>
			#formClose()#
			
			<script type="text/javascript">
				jQuery(document).on('keyup','##filterSet_Search input, ##filterSet_Search select',function(e){
					if(e.keyCode != 9 && (e.keyCode > 40 || e.keyCode < 37)){
						console.log('hi');
						Fund.throttle(Fund.query,'fundsearch',500);
					}
				})
			</script>
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
	</cffunction>
	
	<!--- --->
	
	<cffunction name="renderLoginForm" access="public" output="true" returntype="string">
		
		<cfset var local = {} />
		
		<cfsavecontent variable="local.result">
			#_renderForm(title="Welcome back",id="login_form",collapse=false)#
				<div style="text-align:center;margin-top:10px;">
					#$.render.img(path='/icons/facebook.png',style="margin:auto;cursor:pointer;",onclick="Login.facebookLogin();")#
				</div>
				
				#renderDivider()#
				
				#renderUsername()#
				#renderPassword()#
				
				<div class="filterSet-buttons">
					<button class="small" onclick="Login.attemptLogin();">#$.render.img(path='/icons/enter_white.png',style="margin-left:-8px;margin-right:2px;margin-bottom:-3px;")#Log In</button>
				</div>
				
				#renderDivider('<a href="javascript:Modal.open(#"'signupForm'"#);">Not Signed Up?</a>')#
			#formClose()#
			
			<script type="text/javascript">
				$(document).ready(function(){
					Modal.init('loginForm','email',188);
				});
			</script>
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
	</cffunction>
	
	<!--- --->
	
	<cffunction name="renderSignupForm" access="public" output="true" returntype="string">
		
		<cfset var local = {} />
		
		<cfset local.formID = "signup_form" />
		
		<cfsavecontent variable="local.result">
			#_renderForm(title="Sign Up For Fundr",id=local.formID,collapse=false)#
				<div style="text-align:center;margin-top:8px;">
					#$.render.img(path='/icons/facebook-connect.png',style="margin:auto;cursor:pointer;height:21px;")#
				</div>
				
				#renderDivider("or use your email")#
				
				<div style="float:left;display:inline-block;">
					<div class="filter-label instructions">#$.render.star()#Email</div>
					<div style="clear:both">
						<input name="email" value="" title="Email" validate="email,required,match1" style="clear:both;"/>
					</div>
					
					<div class="filter-label instructions">#$.render.star()#Confirm Email</div>
					<div style="clear:both">
						<input name="email2" value="" title="Email" validate="email,required,match1" />
					</div>
					
					<div class="filter-label instructions">#$.render.star()#Password</div>
					<div style="clear:both">
						<input name="password" title="Password" type="password" value="" validate="required,match2" />
					</div>
					
					<div class="filter-label instructions">#$.render.star()#Confirm Password</div>
					<div style="clear:both">
						<input name="password2" title="Password" type="password" value="" validate="required,match2" />
					</div>
				</div>
				
				<div style="float:right;display:inline-block;">
					<div class="filter-label instructions" style="width:100px;">
						#$.render.star()#First Name
					</div>
					<div class="filter-label instructions">
						Middle Initial
					</div>
					<div style="clear:both">
						<input name="first_name" value="" title="First Name" validate="required" style="width:120px;"/>
						<input name="middle_name" value="" title="Middle Initial" validate="maxlength1" style="width:30px;"/>
					</div>
					
					<div class="filter-label instructions">#$.render.star()#Last Name</div>
					<div style="clear:both">
						<input name="last_name" value="" title="Last Name" validate="required" />
					</div>
					
					#renderLocationFilter(required=true)#
				</div>
				
				<div style="clear:both;"></div>

				<div class="filterSet-buttons">
					<button class="small" onclick="Login.createUser();">#$.render.img(path='/icons/enter_white.png',style="margin-left:-8px;margin-right:2px;margin-bottom:-3px;")#Sign Up</button>
				</div>
				
			#formClose()#
			
			<script type="text/javascript">
				$(document).ready(function(){
					Modal.init('signupForm','email',334,348);
				});
				jQuery(document).on('keyup','##filterSet_signup_form input, ##filterSet_signup_form select',function(e){
					if(e.keyCode == 13){
						Login.createUser();
					}
				})
			</script>
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
	</cffunction>
	
	<!--- --->
	
	<cffunction name="renderIDFilter" access="public" output="true" returntype="string">

		<cfset var local = {} />
		
		<cfsavecontent variable="local.result">
			<div class="filter-label instructions" bubble="This is the bubble message!." />
				Fund ID
			</div>
			<input name="fundID" value="" validate="" placeholder="example: FND1R4"/>
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
	</cffunction>
	
	<!--- --->
	
	<cffunction name="renderLocationFilter" access="public" output="true" returntype="string">
		<cfargument name="required" required="false" default="false" />
		<cfargument name="no_star" required="false" default="false" />
		<cfargument name="query_onchange" required="false" default="Fund.throttle(Fund.query,'fundsearch',500);" />
		
		<cfset var local = {} />
		
		<cfsavecontent variable="local.result">
			<div class="filter-label instructions" bubble="This is another bubble message?!.">
				<cfif arguments.required and not arguments.no_star>#$.render.star()#</cfif>City
			</div>
			<div style="clear:both;">
				<input name="City" value="" title="City" style="" <cfif arguments.required>validate="required"</cfif>/>
			</div>
			
			<div class="filter-label instructions" style="width:50px;">
				<cfif arguments.required and not arguments.no_star>#$.render.star()#</cfif>State	
			</div>
			<div class="filter-label instructions">
				<cfif arguments.required and not arguments.no_star>#$.render.star()#</cfif>Postal Code	
			</div>
			<div style="clear:both;">
				#$.render.select(
					name="state_ID",
					label="State",
					query=$service.resourceService.getStates(),
					blank=true,
					required=arguments.required,
					onchange=arguments.query_onchange
				)#
				<input name="Zip" title="Postal Code" value="" style="width:114px;" validate="integer,maxlength5<cfif arguments.required>,required</cfif>" />
			</div>

		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
	</cffunction>
	
	<!--- --->
	
	<cffunction name="renderOwnerFilter" access="public" output="true" returntype="string">

		<cfset var local = {} />
		
		<cfsavecontent variable="local.result">
			<div class="filter-label instructions">
				Fund Owner Name
			</div>
			<input name="owner_name" value="" validate="" />
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
	</cffunction>
	
	<!--- --->
	
	<cffunction name="renderTitleDescriptionFilter" access="public" output="true" returntype="string">

		<cfset var local = {} />
		
		<cfsavecontent variable="local.result">
			<div class="filter-label instructions">
				Fund Title or Description
			</div>
			<input name="title_description" value="" validate="" />
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
	</cffunction>
	
	<!--- --->
	
	<cffunction name="renderDateRangeFilter" access="public" output="true" returntype="string">

		<cfset var local = {} />
		
		<cfsavecontent variable="local.result">
				<div class="filter-label instructions" bubble="Enter a Date Range.">
					Fund Created Date
				</div>
			<div style="clear:both">
			</div>
			<input name="start_date" validate="date" value="" style="width:69px;"/><span class="instructions" style="padding:3px;">to</span><input name="start_date" validate="date" value="" style="width:69px;"/>
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
	</cffunction>
	
	<!--- --->
	
	<cffunction name="renderUserName" access="public" output="true" returntype="string">

		<cfset var local = {} />
		
		<cfsavecontent variable="local.result">
			<div class="filter-label instructions">
				Email
			</div>
			<input name="email" value="" title="Email" validate="email,required" onkeyup="if(event.keyCode == 13){Login.attemptLogin();};" />
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
	</cffunction>
	
	<!--- --->
	
	<cffunction name="renderPassword" access="public" output="true" returntype="string">

		<cfset var local = {} />
		
		<cfsavecontent variable="local.result">
			<div class="filter-label instructions">
				Password
			</div>
			<input name="password" title="Password" type="password" value="" validate="required" onkeyup="javascript:if(event.keyCode == 13){Login.attemptLogin();};" />
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
	</cffunction>
	
	<!--- --->
	
	<cffunction name="renderDivider" access="public" output="true" returntype="string">
		<cfargument name="text" required="false" default="or" />

		<cfset var local = {} />
		
		<cfsavecontent variable="local.result">
			<table cellspacing="0" cellpadding="0">
				<tr>
					<td width="50%" style="padding:0px 5px;"><div style="display:inline-block;width:100%;border-top:1px solid ##999999;height:2px;"></div></td>
					<td width="0%" style="text-align:center;white-space:nowrap;">
						<span class="instructions">#arguments.text#</span>
					</td>
					<td width="50%" style="padding:0px 5px;"><div style="display:inline-block;width:100%;border-top:1px solid ##999999;height:2px;"></div></td>
				</tr>
			</table>
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
	</cffunction>
	
	<!--- --->
	
	<cffunction name="renderFeatures" access="public" output="true" returntype="string">
		
		<cfset var local = {} />
		
		<cfsavecontent variable="local.result">
			<style type="text/css">
				.complete{
					text-decoration:line-through;
				}
				.feature{
					width:168px;
					font-size:12px;
					line-height:12px;
					color:##6b6b6b;
				}
				.sub{
					margin-left:10px;
					width:158px;
				}
				.sub:before{
					content:"- ";
				}
			</style>
			#_renderForm("logins")#
				<div class="feature">peter@fundr.us</div>
					<div class="feature sub">password:welcome</div>
				<div class="feature">david@fundr.us</div>
					<div class="feature sub">password:welcome</div>
				<div class="feature">test@fundr.us</div>
					<div class="feature sub">password:welcome</div>
				<div class="feature">sarah@fundr.us</div>
					<div class="feature sub">password:welcome</div>
				<div class="feature">amy@fundr.us</div>
					<div class="feature sub">password:welcome</div>
				<div class="feature">chris@fundr.us</div>
					<div class="feature sub">password:welcome</div>

				<!--- <div class="feature">Tag Filters</div>
					<div class="feature sub">Click to populate</div>
				<div class="feature complete">Self saving modals</div>
				<div class="feature complete">Form validation</div>
				<div class="feature complete">Banner</div>
					<div class="feature sub">Banner live links</div>
					<div class="feature sub">Banner categories</div>
					<div class="feature sub complete">Banner dot hover</div>
				<div class="feature complete">Reskinned radio buttons</div>
				<div class="feature complete">Create Fund form</div>
					<div class="feature sub complete">Login redirect to my funds</div>
				<div class="feature complete">Login form</div>
					<div class="feature sub">Facebook integration</div>
				<div class="feature complete">Signup form</div>
					<div class="feature sub">Facebook integration</div>
				<div class="feature complete">Left filter groups</div>
					<div class="feature sub complete">Collapsible groups</div>
					<div class="feature sub complete">scrollable filters</div>
					<div class="feature sub">save collapse state</div>
				<div class="feature complete">Favorites button</div>
				<div class="feature">Support Fund</div>
				<div class="feature">My Fund Tabs</div>
				<div class="feature">Photo Uploads</div>
				<div class="feature complete">Hover chat bubble help</div>
				<div class="feature complete">Process payment</div> --->
			#formClose()#
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
	</cffunction>
	
	<!--- --->
	
	<cffunction name="renderSession" access="public" output="true" returntype="string">
		
		<cfset var local = {} />
		
		<cfsavecontent variable="local.result">
			<script>
				reloadSession = function(){
					Ajax.run(
						"filterView.renderSession",
						function(data){
							jQuery("##filter_Session").fadeOut(function(){
								jQuery('##filter_Session').parent().replaceWith(data);							
							});
						}
					);
				};
			</script>
			#_renderForm("Session")#
				<a href="javascript:reloadSession();">refresh</a>
				<div class="instructions" style="text-decoration:underline;font-size:10px;width:168px;"><cfif structkeyExists(session,"id")>#session.id#<cfelse>no sessionid</cfif></div>
				<div class="filter-label instructions">
					user.funds : #session.user.funds#
				</div>
				</br>
				<div class="filter-label instructions">
					user.id : #left(session.user.id,16)#
				</div>
				<div class="filter-label instructions">
					-#right(session.user.id,16)#
				</div>
				</br>
				<div class="filter-label instructions">
					user.name : #session.user.name#
				</div>
				</br>
				<div class="filter-label instructions">
					user.payments : #session.user.payments#
				</div>
				</br>
				<div class="filter-label instructions">
					user.favorites :<cfloop list="#session.user.favorites#" index="local.i"></br>#local.i#</cfloop>
				</div>
				</br>
				<div class="filter-label instructions">
					<cfif structKeyExists(cookie,"ip")>
					IP:#cookie.ip#
					</cfif>
				</div>
				<div class="filter-label instructions" style="font-size:10px;">
					<cfif structKeyExists(cookie,"id")>
					ID:#cookie.id#
					</cfif>
				</div>
			#formClose()#
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
	</cffunction>
	
	<!--- --->
	
	<cffunction name="renderSorting" access="public" output="true" returntype="string">
		
		<cfset var local = {} />
		
		<cfsavecontent variable="local.result">
			<div class="filter-label instructions" style="width:90px;margin-left:10px;">
				My Funds#$.render.img(path='icons/star_green.png',style="height:13px;margin-bottom:-2px;")#
			</div>
			<div class="filter-label instructions">
				Favorites#$.render.img(path='icons/star_gold.png',style="height:13px;margin-bottom:-2px;")#
			</div>
			<div style="clear:both;"></div>
			<div style="margin-top:3px;overflow:visible;">
				<div style="display:inline-block;float:left;margin-right:7px;">
					#$.render.radio(name="show_mine",value=1,labels=["Show","Hide"],onchange="Fund.throttle(Fund.query,'fundsearch',500);")#
				</div>
				<div style="display:inline-block;float:left;">
					#$.render.radio(name="show_favorites",value=1,labels=["Show","Hide"],onchange="Fund.throttle(Fund.query,'fundsearch',500);")#
				</div>
			</div>
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
	</cffunction>
	
	<!--- --->
	
	<cffunction name="renderUploadForm" access="public" output="true" returntype="string">
		
		<cfset var local = {} />
		
		<cfset local.id = 'upload_form' />
				
		<cfset local.s3 = $.format.s3signature() />
		
		<cfsavecontent variable="local.result">
			#_renderForm(title="Upload Photo",id=local.id,collapse=false)#
				<form action="https://s3.amazonaws.com/FundrImages" method="post" enctype="multipart/form-data" target="theUploadIframe">
					<input type="hidden" name="key" value="test.test.jpg">
					<input type="hidden" name="AWSAccessKeyId" value="AKIAJBZNJ2EZXTDOEQNQ"> 
					<input type="hidden" name="acl" value="public-read">
					<input type="hidden" name="success_action_redirect" value="#$.site.getVar('uploadURL')#">
					<input type="hidden" name="policy" value="#local.s3.policy#" />
					<input type="hidden" name="signature" value="#local.s3.signature#" />
					<input type="hidden" name="Content-Type" value="image/jpeg">
					<input type="file" name="file" onclick="Upload.removeMessage();" onchange="Upload.fileSelected(this);" style="width:196px;"/>
					<div class="filterSet-buttons">
						<button id="uploadButton" type="button" onclick="Upload.submit();" style="display:none;" class="small">#$.render.img(path='/icons/upload.png',style="margin:0px 5px -2px -4px;")#Upload</button>
					</div>
				</form>
				
				<table id="temp-photo-table" width="100%" cellspacing="0" cellpadding="0" style="display:none;">
					<tr>
						<td>
							<div id="temp-photo-div">
								<img id="temp-photo" src="//:0" style="border:2px solid rgb(214,214,214);border-radius:3px;min-height:95px;" />
							</div>
						</td>
						<td style="vertical-align:top;padding:2px 3px 0px 5px;">
							<div id="thumbnail-div">
								<div id="thumbnail-text">
									#$.render.img(path='/icons/star_green.png',class='fund-favorite',bubble="This is Your Fund.",style="margin-left:-5px;")#
									<span class="fund-title">Thumbnail</span>
								</div>
								<div id="thumbnail">
									<img id="thumbnail-photo" src="//:0" style="" />
								</div>
							</div>
							<div class="filterSet-buttons">
								<button id="setThumbnailButton" type="button" onclick="Upload.saveThumbnail();" style="" class="small">#$.render.img(path='/icons/upload.png',style="margin:0px 5px -2px -4px;")#Set Thumbnail</button>
							</div>
						</td>
					</tr>
				</table>
				
			#formClose()#
			
			<script type="text/javascript">
				$(document).ready(function(){
					Modal.init('#local.id#','email',188);
				});
				
				Modal.callback.#local.id# = Upload.init;
			</script>
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
	</cffunction>
	
	<!--- --->
	
	<cffunction name="renderTagForm" access="public" output="true" returntype="string">
		
		<cfset var local = {} />
		
		<cfset local.id = 'tag_form' />
		
		<cfsavecontent variable="local.result">
			#_renderForm(title="Tag Contacts",id=local.id,collapse=false)#
				<input validate="nospace,nocomma,maxlength13" name="contactTag" placeholder="tag here">
				<input type="hidden" name="contactTagfundID" value="" />
				<div class="contactTag hidden" onclick="Mailing.fillTag($(this).text());">test</div>
				<div class="filterSet-buttons">
					<button class="small" onclick="Mailing.saveTags();">save</button>
				</div>
			#formClose()#
			
			<script type="text/javascript">
				$(document).ready(function(){
					Modal.init('#local.id#','contactTag',188);
				});
			</script>
		</cfsavecontent>
		
		<cfreturn $.render.clean(local.result) />
	</cffunction>
	
	<!--- --->

</cfcomponent>